﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Job.Logic.Common;
using Job.Data.Interfaces;
using Job.Entity;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Job.Web.Framework;
namespace Job.Logic.BaseContent
{
    public class BaseContentLogic
    {
        private readonly ICommon commonDao = DataAccess.commonDao;
        private readonly IJobBaseContentDao baseContentDao = DataAccess.jobBaseContentDao;
        private readonly IJobAdvanceCustomerDao advDao = DataAccess.advanceCustomerDao;

        public void Insert(JobBaseContent baseContent)
        {
            baseContentDao.Insert(baseContent);
        }

        public void Update(JobBaseContent baseContent)
        {
            baseContentDao.Update(baseContent);
        }

        public JobBaseContent GetContent(int contentId)
        {
            return baseContentDao.Find(contentId);
        }

        public JobBaseContent GetContentByContentId(int contentId)
        {
            return baseContentDao.Find(contentId);
        }
        public JobBaseContent QuickGetContentByContentId(int contentId)
        {
            return baseContentDao.QuickFind(contentId);
        }

        public JobBaseContent GetContentBySubjectId(int subjectId)
        {
            IList<JobBaseContent> list = baseContentDao.FindBySubjectId(subjectId);
            if (list != null && list.Count >0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
        public JobBaseContent QuickGetContentBySubjectId(int subjectId)
        {
            IList<JobBaseContent> list = baseContentDao.QuickFindBySubjectId(subjectId);
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }
        }

        public void Delete(JobBaseContent content)
        {
            baseContentDao.Delete(content);
        }
        

        public DataSet GetBaseContentList(int pageSize, int pageIndex, int countType, string sortField, SortDirection sortDirection, ArrayList paramList)
        {
            string sql = @"select content_id,title,description,status_id,order_no,
                            subject_id,count,last_update_time,last_update_user
                            from job_base_content where status_id = 1 ";

            foreach (SqlParameter param in paramList)
            {
                switch (param.ParameterName)
                {
                    case "subject_id":
                        sql += " and subject_id = " + param.Value + "";
                        break;
                }
            }

            CommonLogic logic=new CommonLogic();
            DataSet ds = logic.GetPageDataBySqlTwoFieldOrder(sql, pageSize, pageIndex, countType, sortField, sortDirection, paramList);
            return ds;
        }


        public void InsertAdvanceCustomer(JobAdvanceCustomer cus)
        {
            advDao.Insert(cus);
        }

        public DataSet GetAdvanceCustomerList(int pageSize, int pageIndex, int countType, string sortField, SortDirection sortDirection, ArrayList paramList)
        {
            string sql = @"select advance_customer_id,title,home_page,file_name,order_no 
                            from job_advance_customer ";

            CommonLogic logic = new CommonLogic();
            DataSet ds = logic.GetPageDataBySql(sql, pageSize, pageIndex, countType, sortField, sortDirection, paramList);
            return ds;
        }

        public JobAdvanceCustomer GetAdvancebyId(int id)
        {
            return advDao.Find(id);
        }

        public void DeleteAdv(int id)
        {
            JobAdvanceCustomer adv = this.GetAdvancebyId(id);
            if (adv != null)
            {
                advDao.Delete(adv);

            }
        }

        public void UpdateAdv(JobAdvanceCustomer adv)
        {
            advDao.Update(adv);
        }

    }
}
